package com.promote.algorithm;

/**
 * @ClassName maxDepth
 * Description 二叉树的最大深度
 * @Author LiZiHao
 * Date 2022/4/10 17:43
 * @Version 1.0
 **/
public class MaxDepth {

    private class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    /**
     * //第一种方式，递归
     * @param root
     * @return
     */
    public int maxDepth(TreeNode root) {

        return root == null ? 0 : Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;

    }
}
